<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>订单支付</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link type="text/css" rel="stylesheet" media="screen" href="__FONT__/css/style.css"/>
    <link type="text/css" rel="stylesheet" media="screen" href="__FONT__/css/media.css"/>
    <script type="text/javascript" src="__FONT__/js/jquery-1.9.1.min.js"></script>
</head>
<body style="background:#f7f7f9;">
    <script>
    	var oid = '{$orderId}';
	    function jsApiCall()
		{
			WeixinJSBridge.invoke(
				'getBrandWCPayRequest',
				{$jsApiParameters},
				function(res){
		            if (res.err_msg == 'get_brand_wcpay_request:ok') {
		            	history.replaceState(1, "美滴滴",'{:U("Order/userOrder")}');
		            	
						var url =  "{:U('Order/orderInfo/id/'.$orderId)}";
						window.location.href = url;
		                $.ajax({
		                	url: '{:U("Pay/paySuccess")}',
		                	data: {id: oid},
		                	success: function (result) {
		                		window.location.href = url;
		                	},
		                	error: function (e, m, s) {
		                		window.location.href = url;
		                	}
		                });
		            }else if(res.err_msg == 'get_brand_wcpay_request:cancel'){
		            	alert('取消支付');
		                var url =  "{:U('Order/rePay/id/'.$orderId)}";
		                history.replaceState(1, "订单列表",'{:U("Order/userOrder")}');
		                
		                window.location.href = url;
		            }else if(res.err_msg == 'get_brand_wcpay_request:fail'){
		            	alert('支付失败');
		                var url =  "{:U('Order/rePay/id/'.$orderId)}";
		                history.replaceState(1, "订单列表",'{:U("Order/userOrder")}')
		                window.location.href = url;
		            }
				}
			);
		}
	    
	    function onBridgeReady(){
			  WeixinJSBridge.call('hideOptionMenu');
		}
		
		if (typeof WeixinJSBridge == "undefined"){
		    if( document.addEventListener ){
		        document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
		    }else if (document.attachEvent){
		        document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
		        document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
		    }
		}else{
		    onBridgeReady();
		}
	
		function callpay()
		{
			if (typeof WeixinJSBridge == "undefined"){
			    if( document.addEventListener ){
			        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
			    }else if (document.attachEvent){
			        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
			        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
			    }
			}else{
			    jsApiCall();
			}
		}
	
		callpay();
    </script>
</body>
</html>